﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.OleDb;
using DTO;
using System.Data;

namespace DAO
{
    public class ChiTietHoaDonDAO:AbstractDAO
    {
        public static bool them(ChiTietHoaDonDTO chiTietHoaDon)
        {
            bool ketQua = true;
            OleDbConnection ketNoi = null;
            try
            {
                ketNoi = KetNoi();
                string chuoiLenh = "INSERT INTO ChiTietHoaDon(MaHoaDon,MaPhieuThue,SoNgayThue,DonGia,ThanhTien,NgayThanhToan)";
                chuoiLenh += " VALUES (@MaHoaDon,@MaPhieuThue,@SoNgayThue,@DonGia,@ThanhTien,@NgayThanhToan)";
                OleDbCommand lenh = new OleDbCommand(chuoiLenh, ketNoi);

                OleDbParameter thamSo;
                thamSo = new OleDbParameter("@MaHoaDon", OleDbType.Integer);
                thamSo.Value = chiTietHoaDon.HoaDon.MaHoaDon;
                lenh.Parameters.Add(thamSo);

                thamSo = new OleDbParameter("@MaPhieuThue", OleDbType.Integer);
                thamSo.Value = chiTietHoaDon.PhieuThue.MaPhieuThue;
                lenh.Parameters.Add(thamSo);

                thamSo = new OleDbParameter("@SoNgayThue", OleDbType.Integer);
                thamSo.Value = chiTietHoaDon.SoNgayThue;
                lenh.Parameters.Add(thamSo);

                thamSo = new OleDbParameter("@DonGia", OleDbType.Integer);
                thamSo.Value = chiTietHoaDon.DonGia;
                lenh.Parameters.Add(thamSo);

                thamSo = new OleDbParameter("@ThanhTien", OleDbType.Double);
                thamSo.Value = chiTietHoaDon.ThanhTien;
                lenh.Parameters.Add(thamSo);

                thamSo = new OleDbParameter("@NgayThanhToan", OleDbType.Date);
                thamSo.Value = chiTietHoaDon.NgayThanhToan;
                lenh.Parameters.Add(thamSo);


                lenh.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                ketQua = false;
            }
            finally
            {
                if (ketNoi != null && ketNoi.State == System.Data.ConnectionState.Open)
                    ketNoi.Close();
            }
            return ketQua;
        }
       
    }
}
